package com.db.williamchart.data;

import ohos.agp.render.LinearShader;
import ohos.agp.render.Shader;
import ohos.agp.utils.Color;
import ohos.agp.utils.Point;
import ohos.agp.utils.Rect;
import ohos.agp.utils.RectFloat;

public class Frame {
    private float left;
    private float top;
    private float right;
    private float bottom;

    public Frame(float left, float top, float right, float bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }
    public Frame modify(float left, float top, float right, float bottom){
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
        return this;
    }
    public Rect toRect(){
        return new Rect( (int)this.left, (int) this.top, (int) this.right, (int) this.bottom);
    }
    public RectFloat toRectFloat(){
        return new RectFloat(toRect());
    }

    public Frame withPaddings(Paddings paddings){
        return new Frame(
                this.left + paddings.getLeft(),
                this.top + paddings.getTop(),
                this.right - paddings.getRight(),
                this.bottom - paddings.getBottom()
        );
    }
    public LinearShader toLinearShader(int[] colors){
        return new LinearShader(
                new Point[]{new Point(this.left,this.top),new Point(this.left,this.bottom)},
                null,
                new Color[]{new Color(colors[0]),new Color(colors[1])},
                Shader.TileMode.MIRROR_TILEMODE
        );
    }

    public boolean contains(float x,float y){
        return left < right && top < bottom && // check for empty first
                x >= left && x < right && y >= top && y < bottom;
    }
    public float getLeft() {
        return left;
    }

    public void setLeft(float left) {
        this.left = left;
    }

    public float getTop() {
        return top;
    }

    public void setTop(float top) {
        this.top = top;
    }

    public float getRight() {
        return right;
    }

    public void setRight(float right) {
        this.right = right;
    }

    public float getBottom() {
        return bottom;
    }

    public void setBottom(float bottom) {
        this.bottom = bottom;
    }

    @Override
    public String toString() {
        return "Frame{" +
                "left=" + left +
                ", top=" + top +
                ", right=" + right +
                ", bottom=" + bottom +
                '}';
    }
}
